package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.SchoolStudentCourseRelationship;
import com.example.demo.entity.dto.CourseGradeDTO;
import com.example.demo.entity.dto.SchoolCourseDeleteDTO;
import com.example.demo.mapper.SchoolStudentMapper;
import com.example.demo.service.SchoolStudentCourseRelationshipService;
import com.example.demo.mapper.SchoolStudentCourseRelationshipMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【school_student_course_relationship】的数据库操作Service实现
* @createDate 2022-07-30 17:18:07
*/
@Service
public class SchoolStudentCourseRelationshipServiceImpl extends ServiceImpl<SchoolStudentCourseRelationshipMapper, SchoolStudentCourseRelationship>
    implements SchoolStudentCourseRelationshipService{

    @Autowired
    SchoolStudentCourseRelationshipService schoolStudentCourseRelationshipService;

    @Autowired
    SchoolStudentCourseRelationshipMapper schoolStudentCourseRelationshipMapper;

    public void deleteCourse(SchoolCourseDeleteDTO schoolCourseDeleteDTO){
        LambdaQueryWrapper<SchoolStudentCourseRelationship> wrapper=new LambdaQueryWrapper();
        wrapper.eq(SchoolStudentCourseRelationship::getCno,schoolCourseDeleteDTO.getCno())
        .eq(SchoolStudentCourseRelationship::getSno,schoolCourseDeleteDTO.getSno());

        this.schoolStudentCourseRelationshipService.remove(wrapper);
    }

    public List<CourseGradeDTO> selectCourseGrade(){
        return schoolStudentCourseRelationshipMapper.selectCourseGrade();
    }

    public SchoolStudentCourseRelationship selectMaxGrade(){
        return this.getOne(new LambdaQueryWrapper<SchoolStudentCourseRelationship>()
                .orderByDesc(SchoolStudentCourseRelationship::getGrade)
                .last("limit 1"));
    }

}




